<template>
  <section class="main">
    <div class="title">
      <span>基本信息</span>
      <div>
        <el-button icon="el-icon-edit" @click="details()">编辑</el-button>
        <el-button icon="el-icon-lx-settings" @click="shopFunc()">功能配置</el-button>
        <!-- <el-button icon="el-icon-refresh" @click="refresh"></el-button> -->
      </div>
    </div>
    <div class="container container1">
      <div class="itemBox">
        <div class="line">
          <div>门店号</div>
          <div>{{ shopNo }}</div>
        </div>
        <div class="line">
          <div>门店名</div>
          <div>{{ shopName }}</div>
        </div>
        <div class="line">
          <div>门店电话</div>
          <div>{{ shopTel }}</div>
        </div>
        <div class="line">
          <div>商户号</div>
          <div>{{ merchantNo }}</div>
        </div>
        <div class="line">
          <div>商户名称</div>
          <div>{{ merchantName }}</div>
        </div>
        <div class="line">
          <div>银联终端号</div>
          <div>{{ terminalNoUni }}</div>
        </div>
        <div class="line">
          <div>支付宝门店ID</div>
          <div>{{ aliShopId }}</div>
        </div>
        <div class="line" v-if="isZhy">
          <div>微信子商户号</div>
          <div>{{ wxMchId }}</div>
        </div>
      </div>
      <div class="itemBox">
        <div class="line">
          <div>门店联系人</div>
          <div>{{ managerName }}</div>
        </div>
        <div class="line">
          <div>联系人手机号</div>
          <div>{{ managerMobile }}</div>
        </div>
        <div class="line">
          <div>门店地址</div>
          <div>{{ shopAddress }}</div>
        </div>
        <div class="line">
          <div>门店状态</div>
          <div>{{ statusName }}</div>
        </div>
        <div class="line">
          <div>创建时间</div>
          <div>{{ createTime }}</div>
        </div>
        <div class="line">
          <div>门店别名</div>
          <div>{{ alias }}</div>
        </div>
        <div class="line" v-if="isZhy">
          <div>微信订单优惠标记</div>
          <div>{{ wxGoodsTag }}</div>
        </div>
      </div>
    </div>
    <!-- 核销通道 -->
    <div class="title" v-if="this.rolesId == 1 || this.rolesId == 8">
      <span>核销通道</span>
      <div>
        启用核销
        <el-switch v-model="enableWf" @change="toggleEnableWf()"></el-switch>
      </div>
    </div>
    <div
      class="container container1"
      v-if="this.rolesId == 1 || this.rolesId == 8"
    >
      <div class="wfBox">
        <div class="thead">
          <span>通道名称</span>
          <span>核销模式</span>
          <span>通道配置</span>
        </div>
        <div class="tbody" v-for="(item, index) in cpchlist" :key="index">
          <div>{{ item.channelName }}</div>
          <div>{{ item.wfModeStr }}</div>
          <div>
            <div
              v-if="item.enableCfg == '1' &&  item.channelType != '10005'"
              class="blue"
              style="width: 100%"
              @click="cpchCfg(item)"
            >
              <span>设置</span>
            </div>
            <div
              v-if="item.enableOprateRpa == '1'"
              class="blue"
              style="width: 100%"
              @click="rapPanel(item)"
            >
              <span>操作</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 标签 -->
    <div
      class="title"
      v-if="
        this.rolesId == 1 ||
        this.rolesId == 2 ||
        this.rolesId == 8 ||
        this.rolesId == 9
      "
    >
      <span>标签</span>
      <div>
        <!-- <el-button type="primary">同步渠道</el-button> -->
        <el-button type="primary" @click="popuptag">添加标签</el-button>
      </div>
    </div>
    <div
      class="container container1"
      v-if="
        this.rolesId == 1 ||
        this.rolesId == 2 ||
        this.rolesId == 8 ||
        this.rolesId == 9
      "
    >
      <el-tag
        class="el_tag"
        v-for="item in adm_tag"
        closable
        @close="handleClose(item.key)"
        :key="item.label"
        effect="plain"
      >
        {{ item.label }}
      </el-tag>
      <el-tag
        class="el_tag"
        v-for="item in cw_tag"
        closable
        @close="handleClose(item.key)"
        type="success"
        :key="item.label"
        effect="plain"
      >
        {{ item.label }}
      </el-tag>
      <el-tag
        class="el_tag"
        v-for="item in fws_tag"
        closable
        @close="handleClose(item.key)"
        type="warning"
        :key="item.label"
        effect="plain"
      >
        {{ item.label }}
      </el-tag>
    </div>
    <!-- 门店详情 -->
    <el-dialog
      v-dialogDrag
      title="详情修改"
      :visible.sync="visible"
      width="60%"
      :close-on-click-modal="false"
    >
      <el-form
        :model="addmendian"
        status-icon
        ref="addmendian"
        label-width="125px"
        class="demo-dynamic store-detail"
      >
        <div class="detail-item">
          <el-form-item :required="true" label="门店名称">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.name"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item :required="true" label="门店电话">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.shopTel"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item :required="true" label="门店地址">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.address"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item :required="true" label="门店联系人">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.contact"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item :required="true" label="联系人手机号">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.contactphone"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="优惠券撤销权限">
            <el-switch
              v-model="chengeqx"
              active-color="#13ce66"
              autocomplete="off"
              :active-value="1"
              :inactive-value="0"
              inactive-color="#ff4949"
            >
            </el-switch>
          </el-form-item>

          <el-form-item label="门店类型描述">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.udfType"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="入账账户名">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.udfAccount"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="门店别名">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.alias"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </div>

        <div class="detail-item">
          <el-form-item label="微信子商户号">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.wxMchId"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="微信子商户appid">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.wxAppid"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="微信订单优惠标记">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.wxGoodsTag"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="银联子商户号">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.mchUniNo"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="银联终端号">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.bank"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="支付宝门店ID">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.aliShopId"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="支付宝授权令牌">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.aliSpmerToken"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="龙支付柜台号">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.longpayPostId"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="龙支付公钥">
            <el-input
              class="store-input"
              type="textarea"
              rows="2"
              v-model.trim="addmendian.longpayPublicKey"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="数币终端号">
            <el-input
              class="store-input"
              type="text"
              v-model.trim="addmendian.ecnyTermId"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="shopupdate()">确定</el-button>
      </span>
    </el-dialog>
    <!-- 门店功能配置 -->
    <el-dialog
      v-dialogDrag
      title="功能配置"
      :visible.sync="shopFuncVisible"
      v-if="
        this.rolesId == 1 ||
        this.rolesId == 5 ||
        this.rolesId == 8
      "
      width="35%"
      :close-on-click-modal="false"
    >
      <el-form ref="form" size="mini" label-position="left" label-width="125px">
        <el-form-item label="支付宝支付开关" prop="delivery">
          <el-switch active-value='1' inactive-value='0' v-model="shopFuncInfo.aliSwitch"></el-switch>
        </el-form-item>
        <el-form-item label="微信支付开关" prop="delivery">
          <el-switch active-value='1' inactive-value='0' v-model="shopFuncInfo.wxSwitch"></el-switch>
        </el-form-item>
        <el-form-item label="云闪付支付开关" prop="delivery">
          <el-switch active-value='1' inactive-value='0' v-model="shopFuncInfo.uniSwitch"></el-switch>
        </el-form-item>
        <el-form-item label="翼支付开关" prop="delivery">
          <el-switch active-value='1' inactive-value='0' v-model="shopFuncInfo.bestpaySwitch"></el-switch>
        </el-form-item>
        <el-form-item label="数币支付开关" prop="delivery">
          <el-switch active-value='1' inactive-value='0' v-model="shopFuncInfo.ecnySwitch"></el-switch>
        </el-form-item>
        <el-form-item label="龙支付开关" prop="delivery">
          <el-switch active-value='1' inactive-value='0' v-model="shopFuncInfo.longpaySwitch"></el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="shopFuncVisible = false">取消</el-button>
        <el-button type="primary" @click="shopFuncUpdate()">确定</el-button>
      </span>
    </el-dialog>
    <!-- 门店核销通道配置 -->
    <el-dialog
      v-dialogDrag
      :title="cpchCfgTitle"
      :visible.sync="cpchCfgVisible"
      width="50%"
      :close-on-click-modal="false"
    >
      <el-form
        :model="editCpchCfg"
        status-icon
        ref="editCpchCfg"
        label-width="110px"
        class="demo-dynamic"
      >
        <div style="width: 100%; justify-content: center; align-items: center">
          <el-form-item :required="true" label="核销模式">
            <el-radio-group v-model.trim="editCpchCfg.wfMode">
              <el-radio label="1">API</el-radio>
              <el-radio label="2" v-if="!pandaEnable">RPA</el-radio>
            </el-radio-group>
          </el-form-item>
          <div v-if="!pandaEnable">
            <el-form-item label="门店通道id">
            <el-input
              class="cpchCfgInput"
              type="text"
              v-model.trim="editCpchCfg.poiId"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          </div>
          <div v-if="pandaEnable">
            <el-form-item label="核销账号">
            <el-input
              class="cpchCfgInput"
              type="text"
              v-model.trim="editCpchCfg.api.account"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          </div>
          <div v-if="pandaEnable">
            <el-form-item label="核销密码">
            <el-input
              class="cpchCfgInput"
              type="text"
              v-model.trim="editCpchCfg.api.password"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          </div>
          <div v-if="cpchCfgApiEnable">
            <div class="wfModeBox">API模式参数</div>
          </div>
          <div v-if="cpchCfgRpaEnable">
            <div class="wfModeBox">RPA模式参数</div>
            <el-form-item label="RPA服务域名">
              <el-input
                class="cpchCfgInput"
                type="text"
                v-model.trim="editCpchCfg.rpa.domain"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="RPA账号">
              <el-input
                class="cpchCfgInput"
                type="text"
                v-model.trim="editCpchCfg.rpa.account"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="RPA密码">
              <el-input
                class="cpchCfgInput"
                type="text"
                v-model.trim="editCpchCfg.rpa.password"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="RPA门店名称">
              <el-input
                class="cpchCfgInput"
                type="text"
                v-model.trim="editCpchCfg.rpa.shopName"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="门店所在城市">
              <el-input
                class="cpchCfgInput"
                type="text"
                v-model.trim="editCpchCfg.rpa.city"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cpchCfgVisible = false">取消</el-button>
        <el-button type="primary" @click="cpchCfgEdit()">确定</el-button>
      </span>
    </el-dialog>
    <!-- 门店RPA核销控制面板 -->
    <el-dialog
      v-dialogDrag
      :title="rpaPanelTitle"
      :visible.sync="rpaPanelVisible"
      width="50%"
      :close-on-click-modal="false"
    >
      <div class="rpa-login">
        <el-form
          :model="editCpchCfg"
          status-icon
          ref="editCpchCfg"
          label-width="110px"
          class="demo-dynamic"
        >
          <el-form-item label="RPA账号">
            <el-input
              class="cpchCfgInput"
              type="text"
              v-model.trim="editCpchCfg.rpa.account"
              autocomplete="off"
              :disabled="true"
              style="width: 70%"
            ></el-input>
            <el-button
              type="primary"
              @click="queryRpaLogin()"
              style="margin-left: 12px"
              >查询登录状态</el-button
            >
          </el-form-item>
        </el-form>
        <div class="wfModeBox">登录操作</div>
        <el-tabs type="border-card" v-model="activeTab">
          <el-tab-pane
            label="APP扫码登录"
            v-if="rpaAppLoginVisible"
            name="rpaAppLogin"
          >
            <div style="text-align: center; margin-bottom: 10px">
              <el-button type="primary" @click="rpaLogin(1)"
                >发送APP扫码登录请求</el-button
              >
            </div>
            <div v-if="showAppLoginQrcode" style="text-align: center">
              <img :src="'data:image/png;base64,' + loginAppImageUrl" />
            </div>
          </el-tab-pane>
          <el-tab-pane
            label="微信扫码登录"
            v-if="rpaWxLoginVisible"
            name="rpaWxLogin"
          >
            <div style="text-align: center; margin-bottom: 10px">
              <el-button type="primary" @click="rpaLogin(2)"
                >发送微信扫码登录请求</el-button
              >
            </div>
            <div v-if="showWxLoginQrcode" style="text-align: center">
              <img :src="'data:image/png;base64,' + loginWxImageUrl" />
            </div>
          </el-tab-pane>
          <el-tab-pane label="短信登录" name="rpaSmsLogin">
            <div style="text-align: center; margin-bottom: 10px">
              <el-button type="primary" @click="rpaLogin(3)"
                >发送验证码</el-button
              >
            </div>
            <el-form
              status-icon
              ref="rpaSmsCode"
              label-width="150px"
              class="demo-dynamic"
            >
              <el-form-item label="输入短信验证码">
                <el-input
                  type="text"
                  v-model.trim="rpaSmsCode"
                  autocomplete="off"
                ></el-input>
                <el-button
                  type="primary"
                  @click="rpaSmsConfirm()"
                  style="margin-left: 12px"
                  >确认登录</el-button
                >
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="账密登录" name="rpaPwdLogin">
            <div style="text-align: center; margin-bottom: 10px">
              <el-button type="primary" @click="rpaLogin(4)"
                >点击登录</el-button
              >
            </div>
            <el-form
              status-icon
              ref="rpaSmsCode"
              label-width="150px"
              class="demo-dynamic"
            >
              <el-form-item label="输入短信验证码">
                <el-input
                  type="text"
                  v-model.trim="rpaPwdSmsCode"
                  autocomplete="off"
                ></el-input>
                <el-button
                  type="primary"
                  @click="rpaLogin(4)"
                  style="margin-left: 12px"
                  >账密登录短信验证</el-button
                >
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-dialog>
    <!-- 标签配置 -->
    <el-dialog
      v-dialogDrag
      title="添加标签"
      :visible.sync="Channeldeploy1"
      width="35%"
      :close-on-click-modal="false"
    >
      <el-transfer
        v-model="usedTags"
        :data="unUsedTags"
        :titles="['未选标签', '已选择标签']"
        filterable
        filter-placeholder="请输入关键词"
      >
        <!--  -->
      </el-transfer>
      <div style="width: 100%; text-align: right; margin-top: 30px">
        <el-button type="primary" @click="Channeldeploy1 = false"
          >取消</el-button
        >
        <el-button type="primary" @click="addLabel()">确定</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import {
  cpchCfgEdit,
  getdimensionTagList,
  getMerchantShop,
  getSelectTagsByRole,
  postDimensionTagRemove,
  postDimensionTagSave,
  rpaQryLogin,
  rpaLogin,
  rpaSmsConfirm,
  shopCpchCfgList,
  shopEnableWf,
  shopupdate,
  shopFuncUpdate,
} from "@/api/api";

export default {
  data() {
    return {
      pandaEnable: false,
      routerDataId: "",
      visible: false,
      shopFuncVisible: false,
      cpchCfgVisible: false,
      rpaPanelVisible: false,
      rpaAppLoginVisible: false,
      rpaWxLoginVisible: false,
      activeTab: "",
      Channeldeploy1: false, //添加标签穿梭框开关
      chengeqx: 0,
      chengeqx1: 0,
      adm_tag: [], //超管 运营标签
      cw_tag: [], //财务标签
      fws_tag: [], //服务商标签
      tag_color: "", //标签颜色
      unUsedTags: [], //添加标签穿梭框 未选择的标签
      usedTags: [], //添加标签穿梭框 已选择的标签
      agentname: "", //服务商名称
      rolesId: "",
      store: "",
      id: "",
      shopNo: "", //门店号
      shopName: "", //门店名
      shopTel: "", //门店电话
      merchantNo: "", //商户号
      merchantName: "", //商户名称
      terminalNoUni: "", //银联终端号
      aliShopId: "", // 支付宝门店ID
      aliSpmerToken: "", // 支付宝授权令牌
      managerName: "", //门店联系人
      managerMobile: "", //联系人手机号
      shopAddress: "", //门店地址
      statusName: "", //门店状态
      alias: "", //门店别名
      wxMchId: "", // 微信子商户号
      wxGoodsTag: "", //微信订单优惠标记
      createTime: "", //创建时间
      enableWf: true, //是否启用核销功能
      cpchlist: "",
      cpchCfgTitle: "",
      cpchCfgApiEnable: false,
      cpchCfgRpaEnable: false,
      rpaPanelTitle: "",
      showAppLoginQrcode: false,
      showWxLoginQrcode: false,
      loginAppImageUrl: "",
      loginWxImageUrl: "",
      longpayPostId: "",
      longpayPublicKey: "",
      mchUniNo: "",
      wxMchId: "",
      wxAppid: "",
      udfType: "",
      udfAccount: "",
      wxGoodsTag: "",
      ecnyTermId: "",
      addmendian: {
        name: "",
        shopTel: "",
        address: "",
        contact: "",
        contactphone: "",
        mchUniNo: "",
        wxMchId: "",
        wxAppid: "",
        udfType: "",
        udfAccount: "",
        bank: "",
        id: "",
        aliShopId: "",
        aliSpmerToken: "",
        longpayPostId: "",
        longpayPublicKey: "",
        wxGoodsTag: "",
        ecnyTermId: "",
      },
      shopFuncInfo: {},
      editCpchCfg: {
        id: "",
        shopId: "",
        wfMode: 1,
        channelType: "",
        poiId: "",
        rpa: {
          domain: "",
          account: "",
          password: "",
          shopName: "",
          city: "",
        },
        api: {
          account: "",
          password: ""
        }
      },
      rpaSmsCode: "",
      rpaPwdSmsCode: "",
      shopinfo: {},
      isZhy: false
    };
  },
  created() {
    this.routerDataId = sessionStorage.getItem("store_id");
    var aaa = sessionStorage.getItem("userInfo");
    var bbb = JSON.parse(aaa);
    this.rolesId = bbb.rolesId;
    this.getMerchantShop(); //获取门店详情
    // this.getStore()
    if (
      this.rolesId == 1 ||
      this.rolesId == 2 ||
      this.rolesId == 8 ||
      this.rolesId == 9
    ) {
      this.getdimensionTagList(); //获取指定对象已拥有的标签
    }
  },
  methods: {
    //修改thead 背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color: #F0F0F0;font-weight: 500;font-size:14px;color:#000;";
      }
    },
    //获取门店详情
    getMerchantShop() {
      getMerchantShop({}, this.routerDataId).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            this.shopinfo = res.data;
            this.shopNo = res.data.shopNo; //门店号1
            this.shopName = res.data.shopName; //门店名
            this.shopTel = res.data.shopTel; //门店电话
            this.merchantNo = res.data.merchantNo; //商户号merchantName
            this.merchantName = res.data.merchantName; //商户名称
            this.terminalNoUni = res.data.terminalNoUni; //银联终端号
            this.managerName = res.data.managerName; //门店联系人
            this.managerMobile = res.data.managerMobile; //联系人手机号
            this.shopAddress = res.data.shopAddress; //门店地址
            this.statusName = res.data.statusName; //门店状态
            this.createTime = res.data.createTime; //创建时间
            this.aliShopId = res.data.aliShopId; //口碑
            this.aliSpmerToken = res.data.aliSpmerToken; // 支付宝授权令牌
            this.alias = res.data.alias; //门店别名
            this.wxGoodsTag = res.data.wxGoodsTag; // 微信优惠标记
            this.id = res.data.id;
            this.chengeqx = res.data.canCancelCoupon;
            this.chengeqx1 = res.data.canCancelCoupon;
            this.longpayPostId = res.data.longpayPostId;
            this.longpayPublicKey = res.data.longpayPublicKey;
            this.mchUniNo = res.data.mchUniNo;
            this.wxMchId = res.data.wxMchId;
            this.wxAppid = res.data.wxAppid;
            this.udfType = res.data.udfType;
            this.udfAccount = res.data.udfAccount;
            this.wxGoodsTag = res.data.wxGoodsTag;
            this.ecnyTermId = res.data.ecnyTermId;
            this.tradeSwitch = res.data.tradeSwitch;
            if (res.data.enableWf == "1") {
              this.enableWf = true;
            } else {
              this.enableWf = false;
            }
            this.cpchCfgList();
          } else {
            this.$message.error(res.message);
          }
        }
      });
    },
    // 详情修改菜单
    details() {
      this.visible = true;
      this.addmendian = {
        name: this.shopName,
        shopTel: this.shopTel,
        address: this.shopAddress,
        contact: this.managerName,
        contactphone: this.managerMobile,
        bank: this.terminalNoUni,
        id: this.id,
        aliShopId: this.aliShopId,
        aliSpmerToken: this.aliSpmerToken,
        alias: this.alias,
        longpayPostId: this.longpayPostId,
        longpayPublicKey: this.longpayPublicKey,
        mchUniNo: this.mchUniNo,
        wxMchId: this.wxMchId,
        wxAppid: this.wxAppid,
        udfType: this.udfType,
        udfAccount: this.udfAccount,
        wxGoodsTag: this.wxGoodsTag,
        ecnyTermId: this.ecnyTermId,
      };

      this.chengeqx = this.chengeqx1;
    },
    // 功能配置
    shopFunc() {
      this.shopFuncVisible = true;
      let tsObj = this.tradeSwitch ? JSON.parse(this.tradeSwitch) : {};
      this.shopFuncInfo = {
        bankSwitch: tsObj.bankSwitch == 0 ? tsObj.bankSwitch.toString() : "1",
        aliSwitch: tsObj.aliSwitch == 0 ? tsObj.aliSwitch.toString() : "1",
        wxSwitch: tsObj.wxSwitch == 0 ? tsObj.wxSwitch.toString() : "1",
        uniSwitch: tsObj.uniSwitch == 0 ? tsObj.uniSwitch.toString() : "1",
        bestpaySwitch: tsObj.bestpaySwitch == 0 ? tsObj.bestpaySwitch.toString() : "1",
        ecnySwitch: tsObj.ecnySwitch == 0 ? tsObj.ecnySwitch.toString() : "1",
        longpaySwitch: tsObj.longpaySwitch == 0 ? tsObj.longpaySwitch.toString() : "1",
      }
    },
    // 修改门店
    shopupdate() {
      shopupdate(
        {
          shopName: this.addmendian.name,
          shopTel: this.addmendian.shopTel,
          shopAddress: this.addmendian.address,
          managerName: this.addmendian.contact,
          managerMobile: this.addmendian.contactphone,
          terminalNoUni: this.addmendian.bank,
          aliShopId: this.addmendian.aliShopId,
          aliSpmerToken: this.addmendian.aliSpmerToken,
          canCancelCoupon: this.chengeqx,
          alias: this.addmendian.alias,
          mchUniNo: this.addmendian.mchUniNo,
          wxMchId: this.addmendian.wxMchId,
          wxAppid: this.addmendian.wxAppid,
          udfType: this.addmendian.udfType,
          udfAccount: this.addmendian.udfAccount,
          longpayPostId: this.addmendian.longpayPostId,
          longpayPublicKey: this.addmendian.longpayPublicKey,
          wxGoodsTag: this.addmendian.wxGoodsTag,
          ecnyTermId:this.addmendian.ecnyTermId,
        },
        this.addmendian.id
      ).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            this.$message({
              message: "修改成功",
              type: "success",
            });
            this.visible = false;
            this.shopName = this.addmendian.name;
            this.shopTel = this.addmendian.shopTel;
            this.shopAddress = this.addmendian.address;
            this.managerName = this.addmendian.contact;
            this.managerMobile = this.addmendian.contactphone;
            this.terminalNoUni = this.addmendian.bank;
            this.aliShopId = this.addmendian.aliShopId;
            this.aliSpmerToken = this.addmendian.aliSpmerToken;
            this.alias = this.addmendian.alias;
            this.longpayPostId = this.addmendian.longpayPostId;
            this.longpayPublicKey = this.addmendian.longpayPublicKey;
            this.wxGoodsTag = this.addmendian.wxGoodsTag;
            this.ecnyTermId = this.addmendian.ecnyTermId;
            this.chengeqx1 = this.chengeqx;
            this.wxMchId = this.addmendian.wxMchId;
            this.wxAppid = this.addmendian.wxAppid;
            this.mchUniNo = this.addmendian.mchUniNo;
            this.udfType = this.addmendian.udfType;
            this.bank = this.addmendian.bank;
            this.udfAccount = this.addmendian.udfAccount;
          } else {
            this.$message.error(res.message);
          }
        }
      });
    },
    // 功能配置
    shopFuncUpdate() {
      let shopFuncContent = {
        bankSwitch: parseInt(this.shopFuncInfo.bankSwitch),
        aliSwitch: parseInt(this.shopFuncInfo.aliSwitch),
        wxSwitch: parseInt(this.shopFuncInfo.wxSwitch),
        uniSwitch: parseInt(this.shopFuncInfo.uniSwitch),
        bestpaySwitch: parseInt(this.shopFuncInfo.bestpaySwitch),
        ecnySwitch: parseInt(this.shopFuncInfo.ecnySwitch),
        longpaySwitch: parseInt(this.shopFuncInfo.longpaySwitch),
      }
      shopFuncUpdate(
        {
          id: this.id,
          tradeSwitch: JSON.stringify(shopFuncContent),
        }
      ).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            this.$message({
              message: "修改成功",
              type: "success",
            });
            this.shopFuncVisible = false;
            this.tradeSwitch = JSON.stringify(shopFuncContent);
          } else {
            this.$message.error(res.message);
          }
        }
      });
    },
    //获取详情数据
    // getStore(){
    //   this.store = sessionStorage.getItem("store")
    //   var data = JSON.parse(this.store)
    //   this.shopNo = data.shopNo//门店号
    //   this.shopName = data.shopName//门店名
    //   this.merchantNo = data.merchantNo//商户号
    //   this.merchantName = data.merchantName//商户名称
    //   this.terminalNoUni = data.terminalNoUni//银联终端号
    //   this.managerName = data.managerName//门店联系人
    //   this.managerMobile = data.managerMobile//联系人手机号
    //   this.shopAddress = data.shopAddress//门店地址
    //   this.statusName = data.statusName//门店状态
    //   this.createTime = data.createTime//创建时间
    //   this.id = data.id
    // },
    //显示添加标签弹框
    // 切换门店启用核销状态
    toggleEnableWf() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      if (this.enableWf) {
        shopEnableWf(this.id).then((res) => {
          if (res.code == 405) {
            sessionStorage.removeItem("token");
            this.$router.push("/login");
          } else {
            if (res.code == 200) {
              this.$message({
                message: "启用成功",
                type: "success",
              });
              loading.close();
            } else {
              this.$message.error(res.message);
              loading.close();
            }
          }
        });
      } else {
        this.$confirm("是否确定禁用门店核销功能?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            shopEnableWf(this.id).then((res) => {
              if (res.code == 405) {
                sessionStorage.removeItem("token");
                this.$router.push("/login");
              } else {
                if (res.code == 200) {
                  this.$message({
                    message: "禁用成功",
                    type: "success",
                  });
                  loading.close();
                } else {
                  this.$message.error(res.message);
                  loading.close();
                }
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
            this.enableWf = true;
            loading.close();
          });
      }
    },
    // 门店核销通道配置清单
    cpchCfgList() {
      shopCpchCfgList(this.id).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            this.cpchlist = res.data;
          } else {
            this.$message.error(res.message);
          }
        }
      });
    },
    // 核销通道配置弹窗
    cpchCfg(item) {
      this.cpchCfgTitle = item.channelName + "核销通道配置";
      // this.cpchCfgApiEnable = item.channelType == '10003' || item.channelType == '10004';
      this.cpchCfgRpaEnable =
        item.channelType == "10003" || item.channelType == "10004"||item.channelType == "10010"||item.channelType == "10011"||item.channelType == "10012"||item.channelType == "10013"||item.channelType == "10014";
      this.pandaEnable = item.channelType == '10006' || item.channelType == '10008'
      this.cpchCfgVisible = true;
      let bizObj = item.bizContent ? JSON.parse(item.bizContent) : {};
      
      let rpa = {
        domain: "",
        account: "",
        password: "",
        shopName: "",
        city: "",
      };
      let api = {
        account: "",
        password: "",
      }
      if (!bizObj.rpa) {
        bizObj.rpa = rpa;
      }
      if (!bizObj.api) {
        bizObj.api = api;
      }
      this.editCpchCfg.id = item.id;
      this.editCpchCfg.shopId = item.shopId ? item.shopId : this.id;
      this.editCpchCfg.wfMode = item.wfMode ? item.wfMode + "" : "1";
      this.editCpchCfg.channelType = item.channelType;
      this.editCpchCfg.poiId = item.poiId;
      this.editCpchCfg.rpa = bizObj.rpa;
      this.editCpchCfg.api = bizObj.api;
    },
    // 编辑门店核销通道配置
    cpchCfgEdit() {
      let bizContent
      if(this.pandaEnable) {
        bizContent = {
          api: this.editCpchCfg.api,
        };
      } else {
        bizContent = {
          rpa: this.editCpchCfg.rpa,
        };
      }
      let editData = {
        id: this.editCpchCfg.id,
        shopId: this.editCpchCfg.shopId,
        wfMode: this.editCpchCfg.wfMode,
        channelType: this.editCpchCfg.channelType,
        poiId: this.editCpchCfg.poiId,
        bizContent: JSON.stringify(bizContent),
      };
      cpchCfgEdit(editData).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            this.$message({
              message: "配置成功",
              type: "success",
            });
            this.cpchCfgList();
            this.cpchCfgVisible = false;
          } else {
            this.$message.error(res.message);
          }
        }
      });
    },
    // RPA面板弹窗
    rapPanel(item) {
      this.rpaPanelTitle = item.channelName + "RPA操作面板";
      this.rpaPanelVisible = true;
      this.loginAppImageUrl = "";
      this.loginWxImageUrl = "";
      this.showAppLoginQrcode = false;
      this.showWxLoginQrcode = false;
      let bizObj = item.bizContent ? JSON.parse(item.bizContent) : {};
      let rpa = {
        domain: "",
        account: "",
        address: "",
        city: "",
      };
      if (!bizObj.rpa) {
        bizObj.rpa = rpa;
      }
      this.editCpchCfg.id = item.id;
      this.editCpchCfg.rpa = bizObj.rpa;
      if (item.channelType == "10004") {
        this.rpaAppLoginVisible = true;
        this.rpaWxLoginVisible = true;
        this.activeTab = "rpaAppLogin";
      } else {
        this.rpaAppLoginVisible = false;
        this.rpaWxLoginVisible = false;
        this.activeTab = "rpaSmsLogin";
      }
    },
    queryRpaLogin() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
        target: document.querySelector(".rpa-login"),
      });
      rpaQryLogin(this.editCpchCfg.id).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            loading.close();
            this.$message.success(res.message);
          } else {
            loading.close();
            this.$message.error(res.message);
          }
        }
      });
    },
    rpaLogin(e) {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
        target: document.querySelector(".rpa-login"),
      });
      let loginType = "";
      let reqData = {};
      if (e == 1) {
        // APP扫码登录
        loginType = "APP";
      } else if (e == 2) {
        // 微信扫码登录
        loginType = "WX";
      } else if (e == 3) {
        // 短信验证码登录
        loginType = "SMS";
      } else if (e == 4) {
        // 账密登录
        loginType = "PWD";
        reqData.captchaCode = this.rpaPwdSmsCode;
      }
      reqData.id = this.editCpchCfg.id;
      reqData.method = loginType;
      rpaLogin(reqData).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            if (res.data.message) {
              this.$message.success("请扫码登录！");
              if (e == 1) {
                this.loginAppImageUrl = res.data.message;
                this.showAppLoginQrcode = true;
              } else if (e == 2) {
                this.loginWxImageUrl = res.data.message;
                this.showWxLoginQrcode = true;
              }
            } else {
              this.$message.error("获取登录二维码失败！");
            }
            loading.close();
          } else {
            loading.close();
            this.$message.error(res.message);
          }
        }
      });
    },
    rpaSmsConfirm() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
        target: document.querySelector(".rpa-login"),
      });
      if (!this.rpaSmsCode) {
        this.$message.error("请输入验证码！");
        loading.close();
        return;
      }
      rpaSmsConfirm(this.editCpchCfg.id, this.rpaSmsCode).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          if (res.code == 200) {
            loading.close();
            this.$message.success(res.message);
          } else {
            loading.close();
            this.$message.error(res.message);
          }
        }
      });
    },
    popuptag() {
      if (this.Channeldeploy1 === false) {
        this.usedTags = [];
      }
      this.Channeldeploy1 = true;
      //获取指定对象可添加标签
      getSelectTagsByRole({
        fid: this.routerDataId,
        roleId: 6,
      }).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          if (this.unUsedTags.length == 0) {
            for (var i = 0; i < res.data.allTags.length; i++) {
              this.unUsedTags.push({
                key: res.data.allTags[i].id,
                label: res.data.allTags[i].name,
              });
            }
          }
          if (this.usedTags.length == 0) {
            for (var i = 0; i < res.data.usedTags.length; i++) {
              this.usedTags.push(res.data.usedTags[i].id);
            }
          }
        } else if (res.code == 500) {
          this.$message.error(res.message);
        }
      });
    },
    // 获取指定对象已拥有的标签
    getdimensionTagList() {
      this.adm_tag = [];
      this.cw_tag = [];
      this.fws_tag = [];
      getdimensionTagList({
        fid: this.routerDataId,
        roleId: 6,
      }).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          for (var i = 0; i < res.data.length; i++) {
            if (
              res.data[i].tagCreatorRole == 1 ||
              res.data[i].tagCreatorRole == 8
            ) {
              this.adm_tag.push({
                key: res.data[i].id,
                label: res.data[i].tagName,
              });
            } else if (res.data[i].tagCreatorRole == 9) {
              this.cw_tag.push({
                key: res.data[i].id,
                label: res.data[i].tagName,
              });
            } else if (res.data[i].tagCreatorRole == 2) {
              this.fws_tag.push({
                key: res.data[i].id,
                label: res.data[i].tagName,
              });
            }
          }
          // if(this.rolesId == 2){
          //   this.adm_tag = []
          //   this.cw_tag = []
          // }
        } else if (res.code == 500) {
          this.$message.error(res.message);
        }
      });
    },
    //给指定对象添加标签
    addLabel() {
      var data = this.usedTags.join(",");
      postDimensionTagSave(
        {
          ids: data,
          fid: this.routerDataId,
          roleId: 6,
          holder: this.shopName,
        },
        this.routerDataId
      ).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          this.$message({
            message: "添加成功",
            type: "success",
          });
          this.Channeldeploy1 = false;
          this.getdimensionTagList();
        } else if (res.code == 500) {
          this.Channeldeploy1 = true;
          this.$message.error(res.message);
        }
      });
    },
    handleClose(id) {
      this.$confirm(`是否确定删除该标签？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postDimensionTagRemove({}, id).then((res) => {
            if (res.code == 405) {
              sessionStorage.removeItem("token");
              this.$router.push("/login");
            } else if (res.code == 200) {
              this.$message({
                message: "删除成功",
                type: "success",
              });
              this.getdimensionTagList();
            } else if (res.code == 500) {
              this.$message.error(res.message);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
};
</script>

<style scoped lang="less">
.title {
  background: #fff;
  padding: 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.container1 {
  width: 100%;
  display: flex;
  margin-bottom: 20px;
  box-sizing: border-box;
}
.container1 .itemBox {
  width: 50%;
}
.container1 .itemBox .line {
  width: 100%;
  display: flex;
  font-size: 14px;
  line-height: 200%;
}
.container1 .itemBox .line div:nth-child(1) {
  width: 20%;
  text-align: left;
}
.container1 .itemBox .line div:nth-child(2) {
  width: 80%;
  text-align: left;
  color: #888888;
}
.container1 {
  width: 100%;
  display: flex;
  margin-bottom: 20px;
  box-sizing: border-box;
  flex-wrap: wrap;
  .attachmentitem {
    width: 16.5%;
    text-align: center;
    margin-bottom: 20px;
    div {
      font-size: 14px;
      &:nth-child(1) {
        margin-bottom: 5px;
      }
    }
  }
  .tbody {
    display: flex;
    padding: 15px 0;
    div {
      width: 30%;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: center;
      font-size: 12px;
    }
  }
}
.red {
  color: red;
}
.tableBox {
  width: 100%;
}
.store-input {
  width: 95%;
}
.el_tag {
  margin-right: 10px;
  margin-bottom: 5px;
}
.el-tag .el-icon-close {
  color: #fff;
}

.wfBox {
  width: 100%;
  .thead {
    border-bottom: 1px solid #dddddd;
    display: flex;
    padding-top: 15px;
    span {
      width: 30%;
      text-align: center;
      display: inline-block;
    }
  }
}

/deep/ .el-dialog__body {
  padding: 5px 20px;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
}

.cpchCfgInput {
  width: 95%;
}

.store-detail {
  display: flex;
}

.detail-item {
  flex: 1;
}

.wfModeBox {
  width: 100%;
  border-bottom: 1px solid #dddddd;
  margin-bottom: 18px;
  padding-bottom: 10px;
}

.blue {
  color: #409eff;
  text-decoration: underline;
  cursor: pointer;
}
</style>
